package classification.elemListRepr;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;

/**
 * 每一个XMLElementList表示每一个XML文档，它将xml表示为element的集合，用于将XML文档映射为空间向量的封装类
 * 
 * @author eDisOn
 * 
 */
public class XMLElementList
{
    private ArrayList<XMLElement>   elemList    = null;

    private String                  elemListID  = "";

    private String                  XMLContent  = "";  // 这个XML文档中所有的Text内容

    private int                     totalVocNum = 0;

    private HashMap<String, String> contentMap  = null;

    public XMLElementList(String listID)
    {
        elemListID = listID;
        this.elemList = new ArrayList<XMLElement>();
    }

    /**
     * 对参数中XMLElementList对象的一个深拷贝
     * 
     * @param copy
     */
    public void copyXMLElemList(XMLElementList copy)
    {
        for (Iterator<XMLElement> it = copy.Iterator(); it.hasNext();)
        {
            XMLElement elem = new XMLElement(it.next());
            this.elemList.add(elem);
        }
    }

    public void addXMLElem(XMLElement elem)
    {
        this.elemList.add(elem);
    }

    public Iterator<XMLElement> Iterator()
    {
        return this.elemList.iterator();
    }

    public XMLElement get(int index)
    {
        return this.elemList.get(index);
    }

    public XMLElement contains(String elemName)
    {
        for (Iterator<XMLElement> it = this.elemList.iterator(); it.hasNext();)
        {
            XMLElement elem = it.next();
            if (elem.getXMLElemName().equals(elemName)) { return elem; }
        }
        return null;
    }

    public ArrayList<XMLElement> getXMLElemList()
    {
        return this.elemList;
    }

    public int getTotalVocNum()
    {
        return this.totalVocNum;
    }

    public void setTotalVocNum(int totalVocNum)
    {
        this.totalVocNum = totalVocNum;
    }

    public String getListID()
    {
        return this.elemListID;
    }
    
    public int getElemNum()
    {
        return this.elemList.size();
    }
}
